export default function useResize(id, sizeW, sizeH) {
  let dom = document.getElementById(id)
  const resize = () => {
    let width = window.innerWidth
    let height = window.innerHeight
    let zoomW = width / sizeW
    let zoomH = height / sizeH
    let zoom = zoomW < zoomH ? zoomW : zoomH
    dom.style.transform = `scale(${zoom})`
    dom.style.transformOrigin = 'center'
    if (zoomW < zoomH) {
      dom.style.top = (height - sizeH) / 2 + 'px'
      dom.style.left = (sizeW * zoom - sizeW) / 2 + 'px'
    } else {
      dom.style.top = (sizeH * zoom - sizeH) / 2 + 'px'
      dom.style.left = (width - sizeW) / 2 + 'px'
    }
  }
  function setResize() {
    window.addEventListener('resize', resize)
    resize()
  }
  function removeResize() {
    window.removeEventListener('resize', resize)
  }
  return { resize, setResize, removeResize }
}
